export class StrUtil {


  public static isBlank(str: string): boolean {
    return str == null || str === '' || str === 'undefined';
  }

  // public static getBase64(img: File, callback: (img: {}) => void): void {
  //   const reader = new FileReader();
  //   reader.addEventListener('load', () => callback(reader.result));
  //   reader.readAsDataURL(img);
  // }

  public static randomStr(length: number): string {
    let num = '';
    for (let i = 0; i < length; i++) {
      num += Math.floor(Math.random() * 10);
    }
    return num;
  }

  public static clone(data: any): any {
    return JSON.parse(JSON.stringify(data));
  }

  public static mobileHide(mobile: string): string {

    if (StrUtil.isBlank(mobile)) {
      return '';
    }

    return mobile.replace(/(\d{3})\d{4}(\d{4})/, '$1****$2');
  }

  public static getBase64(file: any): Promise<string | ArrayBuffer | null> {
    return new Promise((resolve, reject) => {
      const reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = () => resolve(reader.result);
      reader.onerror = error => reject(error);
    });
  }
}
